package com.abso.sunlight.explorer.editors;

import org.apache.commons.lang.ObjectUtils;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;

import com.abso.sunlight.explorer.LegislatorSearch;
import com.abso.sunlight.explorer.SunlightImages;

/**
 * A specialized input for the editor able to display a list of legislators.
 */
public class LegislatorListEditorInput implements IEditorInput {

    /** The legislator's search. */
    private LegislatorSearch search;

    /**
     * Constructs a new input.
     * 
     * @param search
     *            the legislator's search, wrapping both the query and the list of legislators.
     */
    public LegislatorListEditorInput(LegislatorSearch search) {
        this.search = search;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IEditorInput#exists()
     */
    public boolean exists() {
        return false;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
     */
    public ImageDescriptor getImageDescriptor() {
        return SunlightImages.LEGISLATORS.getDescriptor();
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IEditorInput#getName()
     */
    public String getName() {
        return search.getName();
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IEditorInput#getPersistable()
     */
    public IPersistableElement getPersistable() {
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IEditorInput#getToolTipText()
     */
    public String getToolTipText() {
        return search.getName();
    }

    @SuppressWarnings("unchecked")
    public Object getAdapter(Class adapter) {
        return null;
    }

    /**
     * Returns the search.
     * 
     * @return the search.
     */
    public LegislatorSearch getSearch() {
        return search;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof LegislatorListEditorInput) {
            return ObjectUtils.equals(search, ((LegislatorListEditorInput) obj).search);
        }
        return false;
    }

}
